<?
load_model('Common');
class APclass extends Common {
	protected $_name ="class";
	protected $_primary = 'class_id';
	
	public function get_class_list(){
		$arr = $this->fetchAll(null,"class_id asc")->toArray();
		return $arr;
	}
	
	public function get_class_index(){
		$db = $this->getAdapter();
		$sql = "select * from zf_class where class_if_show=1 order by class_id asc limit 10";
		return $db->fetchAll($sql);
	}
	
	public function get_artclass_list(){
		$db = $this->getAdapter();
		$sql = "select a.*,count(b.art_id) as art_count from zf_class as a left join zf_article as b on a.class_id=b.art_classid where a.class_if_show=1 and a.class_top=1 group by a.class_id order by a.class_id asc ";
		return $db->fetchAll($sql);
	}
	public function get_phoclass_list(){
		$arr = $this->fetchAll("class_top=2","class_id asc")->toArray();
		return $arr;
	}
	public function get_pholist($fid){
		$arr = $this->fetchAll("class_top=2 and class_fid=$fid","class_id asc")->toArray();
		return $arr;
	}
	
	public function get_class_fid($cid){
		$db = $this->getAdapter();
		$where = $db->quoteInto('class_id = ?', $cid);
		$row = $this->fetchRow($where)->toArray();
		return $row["class_fid"];
	}
	/**
	 * 获取前端相册列表
	 *
	 * @param unknown_type $pholist
	 * @return unknown
	 */
	public function get_pholists($fid){
		$arr = $this->fetchAll("class_top=2 and class_fid=$fid","class_id asc")->toArray();
		return $arr;
	}
	
	public function get_class_info($id){
		$db = $this->getAdapter();
		$where = $db->quoteInto('class_id = ?', $id);
		return $this->fetchRow($where)->toArray();
	}
	
	public function get_classname_by_id($id){
		if(!$row = $this->get_class_info($id)){
			return '无';
		}else{
			return $row["class_name"];
		}
		
	}
	
	function add_class($data){
		$dataInsert = array(
		    'class_id' => $data['class_id'],
		    'class_fid' => $data['class_fid'],
		    'class_name' => $data['class_name'],
		    'class_level' => $data['class_level'],
		    'class_top' => $data['class_top'],
		    'class_if_show' => $data['class_if_show'],
		);
		return $this->insert($dataInsert);
	}
	
	function update_class($id, $data){
		$db = $this->getAdapter();
		$where = $db->quoteInto('class_id = ?', $id);
		return $this->update($data, $where);
	}
	
	function del_class($id){
		$db = $this->getAdapter();
		$where = $db->quoteInto('class_id = ?', $id);
		return $this->delete($where);
	}
	
}

?>